<?php
	session_start();
	require_once('functions.php');
	
	if( $_SESSION['account_type_code'] != 1 && $_SESSION['account_type_code'] != 2) 
	{
		header("Location:index.php?response_msg=Please login.");
		exit;
	}
	
	$sailor_id = $_SESSION['sid'];
	$boat_id = $_REQUEST['boat_id'];
	$day = $_REQUEST['day'];
	$action = $_REQUEST['action'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>SAILOR</title>
</head>

<body>
	<a href="user.php">Go Back to user home</a>
	<hr/>
	
	<h2 style="color:red">
		<?php
			if($_REQUEST['response_msg']) 
			{
				echo htmlspecialchars($_REQUEST['response_msg']);
				$_REQUEST['response_msg'] = '';
			}
		?>
	</h2>
	
	<h2>Reserve a boat:</h2>
	
	<form method="get" action="add_new_reservation.php">
		<label for="boat_id">Boat Name: </label>
			<select name="boat_id">
				<?php
				$boat_list = get_boat_list();
					foreach($boat_list as $boat)
					{
				?>
						<option value="<?php echo $boat['bid'] ?>"><?php echo htmlspecialchars($boat['bname']); ?></option>
				<?php
					}
				?>
		</select>
		<br/>
		
		<label for="date">Date: --- </label>
		<label for="month">Month: </label>
		<select name="month">
			<option value="1">Jan</option>
			<option value="2">Feb</option>
			<option value="3">Mar</option>
			<option value="4">Apr</option>
			<option value="5">May</option>
			<option value="6">Jun</option>
			<option value="7">Jul</option>
			<option value="8">Aug</option>
			<option value="9">Sep</option>
			<option value="10">Oct</option>
			<option value="11">Nov</option>
			<option value="12">Dec</option>
		</select>
		
		<label for="day">Day: </label>
		<input type="text" name="day" value=""  maxlength="2">
	
		<label for="year">Year: </label>
		<select name="year">
			<option value="2012">2012</option>
			<option value="2013">2013</option>
		</select>
		
		<input type="hidden" name="sailor_id" value="sailor_id">
		
		<input type="reset" name="" value="Reset">
		<input type="submit" name="" value="Reserve">
	</form>
	
	<hr/>
	<h2>My reservations:</h2>
	
	<?php
		$reservation_list = get_reservation_list($sailor_id);
	?>	
		<input type="text" name="" value="Boat Name" disabled="disabled">
		<input type="text" name="" value="Day" disabled="disabled">
		<input type="text" name="" value="Status" disabled="disabled">
		<input type="text" name="" value="Cancel" disabled="disabled">
		<br/>
	<?php	
		foreach($reservation_list as $reservation)
		{
	?>
				
				<form method="post" action="cancel_reservation.php" style="display:inline;" onsubmit="return confirm('Are you sure you want to cancel this reservation?');">
					<input type="text" name="boat_name" value="<?php echo $reservation['boat_name'] ?>" >
					<input type="text" name="date" value="<?php echo $reservation['day'] ?>" >
					<input type="text" name="status" value="<?php echo $reservation['status'] ?>" >
					
					<input type="hidden" name="boat_id" value="<?php echo $reservation['boat_id'] ?>" >
					<input type="hidden" name="sailor_id" value="<?php echo $sailor_id ?>" >

					<?php
						if($reservation['status'] != "Cancelled")
						{
					?>	
							<input type="submit" name="" value="Cancel Reservation">
						
					<?php
						}
					?>
				</form>
				
				<br/>


	<?php
		}
	?>
	
</body>
</html>